package com.zczc.dao.api.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zczc.dao.api.MessageGetterDao;
import com.zczc.dao.mapper.MessageGetterMapper;
import com.zczc.dao.mapper.MessageUserMapper;
import com.zczc.entity.MessageGetter;
import com.zczc.entity.MessageUser;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 9:25 2018-12-13
 * @Modify by:
 */
@Repository
public class MessageGetterDaoImpl implements MessageGetterDao {

  @Autowired
  private MessageGetterMapper messageGetterMapper;

  @Override
  public Integer addMessageGetter(MessageGetter messageGetter) {
    return messageGetterMapper.insertSelective(messageGetter);
  }

  @Override
  public PageInfo<MessageGetter> selectMessageByPage(MessageGetter messageGetter, Integer pageNum,
      Integer pageSize) {
    PageHelper.startPage(pageNum,pageSize);
    Example example=new Example(MessageGetter.class);
    Criteria criteria = example.createCriteria();
    criteria.andEqualTo("userId",messageGetter.getUserId());
    return PageInfo.of(messageGetterMapper.selectByExample(example));
  }

  @Override
  public Integer deleteMessageByIdLogic(List<String> ids,MessageGetter messageGetter) {
    Example example=new Example(MessageGetter.class);
    Criteria criteria = example.createCriteria();
    criteria.andIn("id",ids);
    criteria.andEqualTo("userId",messageGetter.getUserId());
    return messageGetterMapper.updateByExampleSelective(messageGetter,example);
  }

  @Override
  public Integer readMessageById(List<String> ids, MessageGetter messageGetter) {
    Example example=new Example(MessageGetter.class);
    Criteria criteria = example.createCriteria();
    criteria.andIn("id",ids);
    criteria.andEqualTo("userId",messageGetter.getUserId());
    return messageGetterMapper.updateByExampleSelective(messageGetter,example);
  }
}
